"""

"""

from kivymd.uix.screen import MDScreen
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.label import MDLabel
from kivymd.uix.button import MDRaisedButton, MDIconButton
from kivymd.uix.card import MDCard
from kivymd.uix.toolbar import MDTopAppBar
from kivymd.app import MDApp

class MainScreen(MDScreen):
    """"""
    
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self._build_ui()
    
    def _build_ui(self):
        """"""
        main_layout = MDBoxLayout(
            orientation='vertical',
            spacing="20dp",
            adaptive_height=True
        )
        
        # 
        toolbar = MDTopAppBar(
            title="",
            right_action_items=[
                ["cog", lambda x: self._open_settings()]
            ]
        )
        main_layout.add_widget(toolbar)
        
        # 
        content_layout = MDBoxLayout(
            orientation='vertical',
            spacing="20dp",
            padding="20dp",
            adaptive_height=True
        )
        
        # 
        welcome_card = MDCard(
            orientation='vertical',
            padding="20dp",
            spacing="10dp",
            size_hint_y=None,
            height="200dp",
            elevation=2
        )
        
        welcome_title = MDLabel(
            text=" ",
            theme_text_color="Primary",
            font_style="H5",
            size_hint_y=None,
            height="40dp"
        )
        welcome_card.add_widget(welcome_title)
        
        welcome_desc = MDLabel(
            text="AI\n• \n• \n• ",
            theme_text_color="Secondary",
            font_style="Body1",
            size_hint_y=None,
            height="120dp"
        )
        welcome_card.add_widget(welcome_desc)
        
        content_layout.add_widget(welcome_card)
        
        # 
        button_layout = MDBoxLayout(
            orientation='vertical',
            spacing="15dp",
            size_hint_y=None,
            height="200dp"
        )
        
        # 
        start_btn = MDRaisedButton(
            text=" ",
            size_hint_y=None,
            height="50dp",
            md_bg_color=self.theme_cls.primary_color
        )
        start_btn.bind(on_press=self._start_processing)
        button_layout.add_widget(start_btn)
        
        # 
        history_btn = MDRaisedButton(
            text=" ",
            size_hint_y=None,
            height="50dp"
        )
        history_btn.bind(on_press=self._view_history)
        button_layout.add_widget(history_btn)
        
        # 
        help_btn = MDRaisedButton(
            text=" ",
            size_hint_y=None,
            height="50dp"
        )
        help_btn.bind(on_press=self._show_help)
        button_layout.add_widget(help_btn)
        
        content_layout.add_widget(button_layout)
        main_layout.add_widget(content_layout)
        
        self.add_widget(main_layout)
    
    def _start_processing(self, instance):
        """"""
        app = MDApp.get_running_app()
        app.navigate_to('upload')
    
    def _view_history(self, instance):
        """"""
        # TODO: 
        pass
    
    def _show_help(self, instance):
        """"""
        # TODO: 
        pass
    
    def _open_settings(self):
        """"""
        app = MDApp.get_running_app()
        app.navigate_to('settings')